package com.example.healkep.echarts;

import com.github.abel533.echarts.axis.CategoryAxis;
import com.github.abel533.echarts.axis.ValueAxis;
import com.github.abel533.echarts.code.LineType;
import com.github.abel533.echarts.code.Magic;
import com.github.abel533.echarts.code.SeriesType;
import com.github.abel533.echarts.code.Symbol;
import com.github.abel533.echarts.code.Tool;
import com.github.abel533.echarts.code.Trigger;
import com.github.abel533.echarts.feature.MagicType;
import com.github.abel533.echarts.json.GsonOption;
import com.github.abel533.echarts.series.Bar;
import com.github.abel533.echarts.series.Line;
import com.github.abel533.echarts.series.Pie;

import java.util.List;
import java.util.Map;

public class EchartOptionUtil {

    public static GsonOption getLineChartOptions(Object[] xAxis, Object[] yAxis) {
        GsonOption option = new GsonOption();
        //option.title("趋势");
        //option.legend("血糖值");
        option.tooltip().trigger(Trigger.axis);
        option.toolbox().show(true).feature(Tool.mark, new MagicType(Magic.bar).show(true), Tool.restore, Tool.saveAsImage);

        ValueAxis valueAxis = new ValueAxis();
        option.yAxis(valueAxis);

        CategoryAxis categorxAxis = new CategoryAxis();
        categorxAxis.axisLine().onZero(false);
        categorxAxis.boundaryGap(true);
        categorxAxis.data(xAxis);
        option.xAxis(categorxAxis);

        Line line = new Line();
        line.smooth(false).name("血糖值").data(yAxis).itemStyle().normal().lineStyle().shadowColor("rgba(0,0,0,0.4)");
        //未测试的虚线：line.smooth(false).name("血糖值").data(yAxis).itemStyle().normal().lineStyle().type(LineType.dashed);

        option.series(line);
        return option;
    }

    public static GsonOption getLineChartOptionsW(Object[] xAxis, Object[] yAxis) {
        GsonOption option = new GsonOption();

        option.tooltip().trigger(Trigger.axis);
        option.toolbox().show(true).feature(Tool.mark, new MagicType(Magic.bar).show(true), Tool.restore, Tool.saveAsImage);

        ValueAxis valueAxis = new ValueAxis();
        option.yAxis(valueAxis);

        CategoryAxis categorxAxis = new CategoryAxis();
        categorxAxis.axisLine().onZero(false);
        categorxAxis.boundaryGap(true);
        categorxAxis.data(xAxis);
        option.xAxis(categorxAxis);

        Line line = new Line();
        line.smooth(false).name("体重(kg)").data(yAxis).itemStyle().normal().lineStyle().shadowColor("rgba(0,0,0,0.4)");
        //未测试的虚线：line.smooth(false).name("血糖值").data(yAxis).itemStyle().normal().lineStyle().type(LineType.dashed);

        option.series(line);
        return option;
    }

    public static GsonOption getLineChartOptionsW2(Object[] xAxis, Object[] yAxis) {
        GsonOption option = new GsonOption();

        option.tooltip().trigger(Trigger.axis);
        option.toolbox().show(true).feature(Tool.mark, new MagicType(Magic.bar).show(true), Tool.restore, Tool.saveAsImage);

        ValueAxis valueAxis = new ValueAxis();
        option.yAxis(valueAxis);

        CategoryAxis categorxAxis = new CategoryAxis();
        categorxAxis.axisLine().onZero(false);
        categorxAxis.boundaryGap(true);
        categorxAxis.data(xAxis);
        option.xAxis(categorxAxis);

        Line line = new Line();
        line.smooth(false).name("体重增长值(kg)").data(yAxis).itemStyle().normal().lineStyle().shadowColor("rgba(0,0,0,0.4)");
        //未测试的虚线：line.smooth(false).name("血糖值").data(yAxis).itemStyle().normal().lineStyle().type(LineType.dashed);

        option.series(line);
        return option;
    }

    public static GsonOption getLineChartOptionsW3(Object[] xAxis, Object[] yAxis1, Object[] yAxis2, Object[] yAxis3 ) {
        GsonOption option = new GsonOption();

        option.tooltip().trigger(Trigger.axis);
        option.toolbox().show(true).feature(Tool.mark, new MagicType(Magic.bar).show(true), Tool.restore, Tool.saveAsImage);

        ValueAxis valueAxis = new ValueAxis();
        option.yAxis(valueAxis);

        CategoryAxis categorxAxis = new CategoryAxis();
        categorxAxis.axisLine().onZero(false);
        categorxAxis.boundaryGap(true);
        categorxAxis.data(xAxis);
        option.xAxis(categorxAxis);

        //线一：虚线最高值
        Line line1 = new Line();
        line1.symbol(Symbol.none).smooth(false).name("推荐最高增长值(kg)").data(yAxis1).itemStyle().normal().lineStyle().type(LineType.dashed).shadowColor("rgba(0,0,0,0.4)");

        //线二：实线实际值
        Line line2 = new Line();
        line2.smooth(false).name("真实增长值(kg)").data(yAxis2).itemStyle().normal().lineStyle().shadowColor("rgba(0,0,0,0.4)");

        //线三：虚线最低值
        Line line3 = new Line();
        line3.symbol(Symbol.none).smooth(false).name("推荐最低增长值(kg)").data(yAxis3).itemStyle().normal().lineStyle().type(LineType.dashed).shadowColor("rgba(0,0,0,0.4)");

        option.series(line1,line2,line3);
        return option;
    }

    public static GsonOption getBarChartOptions(Object[] xAxis, Object[] yAxis) {
        GsonOption option = new GsonOption();
        //option.title("趋势");
        //option.legend("血糖值");
        option.tooltip().trigger(Trigger.axis);
        option.toolbox().show(true).feature(Tool.mark, new MagicType(Magic.line).show(true), Tool.restore, Tool.saveAsImage);

        ValueAxis valueAxis = new ValueAxis();
        option.yAxis(valueAxis);

        CategoryAxis categorxAxis = new CategoryAxis();
        categorxAxis.axisLine().onZero(false);
        categorxAxis.boundaryGap(true);
        categorxAxis.data(xAxis);
        option.xAxis(categorxAxis);

        Bar bar = new Bar();
        bar.name("平均值").data(yAxis).itemStyle().normal().lineStyle().shadowColor("rgba(0,0,0,0.4)");
        option.series(bar);
        return option;
    }

    public static GsonOption getPieChartOptions(List<Map<String, Object>> data) {
        GsonOption option = new GsonOption();
        //option.title("饼图");
        //option.legend("输出");
        option.tooltip().trigger(Trigger.axis);

        Pie pie = new Pie();
        pie.name("hello");
        pie.type(SeriesType.pie);
        pie.radius("55%");
        pie.itemStyle().emphasis().shadowBlur(10).shadowOffsetX(0).shadowColor("rgba(0, 0, 0, 0.5)");
        pie.setData(data);//data是传入的参数

        option.series(pie);
        return option;
    }
}
